package Day;

import java.io.StringReader;

public class Day7 {
    public static void main(String[] args) {
        String s="A%sC%sD";
        char[]arg={'B','E','F'};
        System.out.println(formatString(s, arg));
    }

    public static String formatString (String str, char[] arg) {
        int i=0;
      while(true){
         String f= str.replaceFirst("%s",arg[i]+"");
         i++;
         if(f==null)break;
      }
      StringBuilder stringBuilder=new StringBuilder(str);
      while(i< arg.length-1){
          stringBuilder.append(arg[i]);
      }
      return stringBuilder.toString();
    }


    public static String formatString1 (String str, char[] arg) {
        StringBuilder s= new StringBuilder("1");
int cur1=0;
int cur2=0;
while(cur1<str.length()){
    if(str.charAt(cur1)=='%'){
        s.append(arg[cur2++]);
    }else {
        s.append(str.charAt(cur1++));
    }
}
while(cur2< arg.length){
    s.append(arg[cur2++]);
}
String ret=s.substring(1,s.length());
return ret;
    }
}
